{include file="public/base"}
<style>
    td,th{text-align: center}
</style>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>商品管理</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form action="{:url('goods/index')}">
                    <div class="row">
                        <div class="col-sm-5 m-b-xs" >
                            {if $shop>0}
                            <a href="javascript:;" onclick="edit('')" class="btn btn-outline btn-info">添加商品</a>
                          	{else}
                          	<a href="javascript:;" class="btn btn-outline"></a>
                            {/if}
                        </div>
                        <div class="col-sm-3" style="position:absolute;left:15%;">
                            <div class="input-group">
                                <input type="text" placeholder="请输入关键词" class="input-sm form-control" name="keywords"> <span class="input-group-btn">
                                        <input type="submit" name="sub" class="btn btn-sm btn-primary"> 搜索 </span>
                            </div>
                        </div>
                    </div>
                    </form>
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th><input type="checkbox" class="i-checks" name="input" onclick="yanzheng(this,'checkbox[]')"></th>
                                <th>id</th>
                                <th>商品</th>
                                <th>规格</th>
                                <th>缩略图</th>
                                <th>商品图片</th>
                                <th>商品简介</th>
                                <th>原始库存</th>
                              	<th>现库存</th>
                                <th>已售数量</th>
                                <th>原价</th>
                                <th>售价</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {foreach name="goodsList" id="goods" key="k"}
                            <tr>
                                <td>
                                    <input type="checkbox" class="i-checks" name="checkbox[]" value="{$goods['gid']}">
                                </td>
                                <td>{$goods['gid']}</td>
                                <td>{$goods['goods']}</td>
                                <td>{$goods['spec']}</td>
                                <td><img src="{$goods['small_img']}" width="100"></td>
                                <td><a href="javascript:;" onclick="lookInfo('{$goods['gid']}',1)">点击查看</a></td>
                                <td><a href="javascript:;" onclick="lookInfo('{$goods['gid']}',2)">点击查看</a></td>
                                <td>{$goods['stock']}</td>
                              	<td>{$goods['stock']-$goods['sold']}</td>
                                <td>{$goods['sold']}</td>
                                <td>{$goods['old_price']}</td>
                                <td>{$goods['price']}</td>
                                <td><a href="javascript:;" onclick="sets({$goods['gid']},{$goods['status']},this)"  class="sets">{if $goods['status']==1}已上架{else}已下架{/if}</a></td>
                                <td><a href="javascript:;" onclick="edit({$goods['gid']})" class="btn btn-outline btn-info">编辑</a></td>
                            </tr>
                            {/foreach}
                            <tr>
                                <td><a href="javascript:;" onclick="DelAll()" class="btn btn-outline btn-danger">批量删除</a></td>
                            </tr>
                            </tbody>
                        </table>
                        <div style="text-align: center;width: 100%;">
                           {$page}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{block name="javascript"}
<script src="ADMIN_JS/plugins/peity/jquery.peity.min.js"></script>
<script src="ADMIN_JS/content.min.js?v=1.0.0"></script>
<script src="ADMIN_JS/plugins/iCheck/icheck.min.js"></script>
<script src="ADMIN_JS/demo/peity-demo.min.js"></script>
<script>
    //$(document).ready(function(){$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})});
    function edit(id)
    {
        if(id!=''){
            var url = '{:url("goods/goodsEdit",["id"=>"goodsId"])}';
            url = url.replace('goodsId',id);
        }else{
            var url = '{:url("goods/goodsAdd")}';
        }
        //自定页
        layer.open({
            type: 2,
            skin: 'layui-layer-demo', //样式类名
            area: ['80%', '80%'], //宽高
            shadeClose: true, //开启遮罩关闭
            content: url
        });
    }
    function lookInfo(id,types)
    {
        if(types==1){
            var url = '{:url("goods/lookImg",["id"=>"goodsId"])}';
        }
        else{
            var url = '{:url("goods/lookSynopsis",["id"=>"goodsId"])}';
        }
        url = url.replace('goodsId',id);
        layer.open({
            type: 2,
            skin: 'layui-layer-demo', //样式类名
            area: ['50%', '80%'], //宽高
            shadeClose: true, //开启遮罩关闭
            content: url
        });
    }
</script>
<script>
    function yanzheng(e,checks)
    {
        var checkboxs=document.getElementsByName(checks);
        for(i=0;i<checkboxs.length;i++)
        {
            checkboxs[i].checked=e.checked;
        }
    }
    function DelAll(){
        var id = new Array();
        var ids = $('[name="checkbox[]"]:checked');
        if(ids.length==0){
            layer.msg('请选择要删除的商品',{icon:2});
            return;
        }
        else{
            ids.each(function(){
                id.push($(this).val());//将选中的值添加到数组chk_value中
            })
        }
        var box = layer.confirm("您确定要删除吗？",function(){
            var loading = layer.msg('正在提交数据，请稍后...', {icon: 16,time:6000});
            $.post('{:url("goods/goodsDel")}',{id:id.join(',')},function(data){
                layer.close(loading);
                if(data.code=='1'){
                    layer.msg(data.msg,{icon:1,time:2000});
                    setTimeout(function(){location.reload();},1500)
                }else{
                    layer.msg(data.msg,{icon:2,time:2000});
                }
            });
        });
    }
    function sets(gid,state,index)
    {
        var url = '{:url("goods/updateStatus",["id"=>"gid"])}';
        url = url.replace('gid',gid);
        if(state == 1){
            var status = 0;
            var texts = '已下架';
        }else{
            var status = 1;
            var texts = '已上架';
        }
        $.ajax({
            type:"post",
            url:url,
            data:{'status':status},
            success:function(res){
                if(res.code==1){
                    layer.msg(res.msg,{icon:6,time:1500});
                    setTimeout(function () {
                        window.location.reload();
                    },1500)
                }else{
                    layer.msg(res.msg,{icon:5,time:1500});
                }
            },
            error:function(){
                layer.msg("信息错误",{icon:5,time:1500});
            }
        })
    }

</script>
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
{/block}